package LeetCode.LeetCode2;

import java.util.Arrays;

/**
 * 航班预订统计
 * @author lumin
 * @date 2022/04/20 15:42
 **/
public class Num1109 {
    public static int[] corpFlightBookings(int[][] bookings, int n) {
        int[][] newNums = new int[n + 2][n + 1];
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                if(i == 0){
                    if(j == 0){
                        newNums[i][j] = 0;
                    }else{
                        newNums[i][j] = j;
                    }
                }else{
                    if(j == 0){
                        newNums[i][j] = i;
                    }
                }
            }
        }
        int row = newNums.length - 1;
        int col = newNums[0].length;
        int i = 0;
        while(i < bookings.length){
            int firstNum = bookings[i][0];
            int lastNum = bookings[i][1];
            int seat = bookings[i][2];
            //m是寻找新数组行一样的元素
            for (int m = 0; m < row; m++) {
                if(newNums[m][0] == firstNum){
                    for (int k = 0; k < col; k++) {
                        if(newNums[0][k] == firstNum){
                            for (int z = firstNum; z <= lastNum; z++) {
                                    newNums[m][k] =seat + newNums[m][k];
                                    k++;
                            }
                            break;
                        }
                    }
                }
            }
            i++;
        }
        for (int c = 1; c < col; c++) {
            int fNum = 0;
            for (int r = 1; r < row + 1; r++) {
                fNum += newNums[r][c];
            }
            newNums[row][c] = fNum;
        }
        int[] fNums = new int[col - 1];
        for (int j = 0; j + 1 < col; j++) {
            fNums[j] = newNums[row][j + 1];
        }
        return fNums;
    }

    public static void main(String[] args) {
        int[][] arr ={{1,2,5},{3,3,35},{1,2,30}};
        System.out.println(Arrays.toString(corpFlightBookings(arr,3)));
    }
}